<?php
/**
 * 基类控制器  所有模块控制器必须继承此控制器
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/03
 * Time: 14:26
 */

namespace app\core;

use app\extensions\XUtils;
use yii;
use yii\web\Controller;

class YpBaseController extends Controller
{
    protected $params      = '';
    protected $request     = '';
    protected $session     = '';
    protected $userService = '';
    protected $httpRequest = '';
    public function init()
    {
        parent::init();
        //所有控制器初始化对应的配置信息
        $this->params  = Yii::$app->params;
        $this->request = Yii::$app->request;
        $this->session = Yii::$app->session;
    }
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'captcha' => [
                'class'           => 'yii\captcha\CaptchaAction',
                'maxLength'       => 4,
                'minLength'       => 4,
                'customFlag'      => true,
                'writeBackground' => true,
                'writeNoice'      => true,
                'writeCure'       => true,
            ],
        ];
    }
    
    /**
     * ajax输出
     * @param $message
     * @param int $code
     * @param array $data
     * @author chenym
     * @since 2017-07-04
     */
    protected function ajaxReturn($code = 1, $message, $data = [])
    {
        //.net那边问题  解析错误
        if (empty($data)) {
            $result = [
                'code'    => $code,
                'message' => $message,
            ];
        } else {
            $result = [
                'code'    => $code,
                'message' => $message,
                'content' => $data,
            ];
        }
        echo \yii\helpers\Json::encode($result);
    }
}
